package com.laoli.myspringboottest.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laoli.myspringboottest.entity.TableA;
import com.laoli.myspringboottest.service.TableAService;
import com.laoli.myspringboottest.mapper.TableAMapper;
import com.laoli.myspringboottest.event.TestEvent;
import com.laoli.myspringboottest.model.TestItem;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author iamli
* @description 针对表【table_a】的数据库操作Service实现
* @createDate 2022-04-27 16:24:47
*/
@Service
@AllArgsConstructor
@Slf4j
public class TableAServiceImpl extends ServiceImpl<TableAMapper, TableA>
    implements TableAService{


    private final ApplicationContext publisher;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void publishEvent() {
        TableA tableA = new TableA();
        tableA.setValue("aaaaa");

        this.save(tableA);

            TestEvent event = new TestEvent(this,new TestItem("tom"));
            log.info("*********************publisher before:"+event.getTestItem().getName());
            publisher.publishEvent(event);
            log.info("*********************publisher after:"+event.getTestItem().getName());

    }
}




